import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/hj_utils/api_service/vid_service.dart';

import '../../../hj_model/home/home_tabs_entity.dart';
import '../../../hj_model/home/module_detail_model.dart';

class PicsSubLogic extends GetxController with GetTickerProviderStateMixin {
  final ModuleData? tagData;
  late PageController pageController = PageController(keepPage: true);
  int selectIndex = 0; //选中
  List<AllSection>? sections;
  PicsSubLogic({this.tagData});

  @override
  onReady() {
    super.onReady();
    sections ??= [];
    sections?.add(AllSection(sectionName: '推荐', sectionID: tagData?.id, type: -100));
    sections?.add(AllSection(sectionName: '最新', sectionID: tagData?.id, type: -101));
    loadData();
  }

  //获取亚模块数据
  loadData() async {
    final resp = await VidService.getModuleDetail(
      tagData?.id ?? "",
      pageNumber: 1,
      pageSize: 30,
      moduleSort: 1,
    );
    if (resp != null) {
      sections?.addAll(resp.allSection ?? []);
    }
    update();
  }

  onToggleItem(int index) {
    if (index != selectIndex) {
      selectIndex = index;
      pageController.jumpToPage(index);
      update();
    }
  }
}
